package com.xjtu.conan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjtu.conan.entity.TheatreCollectInfo;
import com.xjtu.conan.entity.TheatreImagesInfo;
import com.xjtu.conan.exception.MyException;
import com.xjtu.conan.mapper.TheatreCollectInfoMapper;
import com.xjtu.conan.mapper.TheatreCommentsInfoMapper;
import com.xjtu.conan.service.TheatreCollectInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * <p>
 * 用户收藏剧场版 服务实现类
 * </p>
 *
 * @author 一只黑猩猩
 * @since 2021-04-19
 */
@Service
public class TheatreCollectInfoServiceImpl extends ServiceImpl<TheatreCollectInfoMapper, TheatreCollectInfo> implements TheatreCollectInfoService {

    @Autowired
    private TheatreCollectInfoMapper collectInfoMapper;

    @Override
    public List<TheatreCollectInfo> getAllCollectByuId(int current, int size, Long uid) {
        Page<TheatreCollectInfo> page = new Page<>(current, size);
        QueryWrapper<TheatreCollectInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", uid);
        collectInfoMapper.selectPage(page, queryWrapper);
        System.out.println(page.getTotal());
        return page.getRecords();
    }

    @Override
    public int addTheatreCollect(TheatreCollectInfo theatreCollectInfo) {
        try {
            return collectInfoMapper.insert(theatreCollectInfo);
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(500, "插入收集信息失败！");
        }
    }

    @Override
    public int updateTheatreCollect(TheatreCollectInfo theatreCollectInfo) {
        try {
            return collectInfoMapper.updateById(theatreCollectInfo);
        } catch (Exception e) {
            throw new MyException(500, "更新收集信息失败！");
        }
    }

    @Override
    public int deleteTheatreCollect(Long tcid) {
        try {
            return collectInfoMapper.deleteById(tcid);
        } catch (Exception e) {
            throw new MyException(500, "删除收集信息失败！");
        }
    }

    @Override
    public int getTotal() {
        return collectInfoMapper.selectCount(null);
    }

}
